package com.dwin.dingnuo.ui.detail.tool;

import java.util.HashMap;
import java.util.Map;

/**
 * 页面初始化：指令查询工具
 */
public class InstructTool extends JsonTool {

    /**
     * 设备详情页面，查询指令
     *
     * @return
     */
    public static Map deviceQuery() {
        Map map = new HashMap();
        map.put(type_CMD, typeR);
        map.put("input_voltage", 0);
        map.put("output_voltage", 0);
        map.put("output_current", 0);
        map.put("output_power", 0);
        map.put("frequency", 0);
        map.put("set_frequency", 0);

        map.put("front_bearing_temperature", 0);
        map.put("back_bearing_temperature", 0);
        map.put("oxygen_content", 0);
        map.put("running_time", 0);
        map.put("electricity_today", 0);
        map.put("electricity_total", 0);
        map.put("on_off", 0); // 设备状态。

        map.put("fault_warning", 0); // 故障预警
        map.put("is_locked", 0); // 设备是否锁定

        // 操作设备：{0x15(21)频率上升；0x16(22)频率下降；0x12(18)启动；
        // 0x13(19)停止；0x11(17)复位；0x10(16)锁定 ；0x09表示解锁。}
        map.put("device_operation", 0);
        map.put("device_status", 0); // 文本显示设备的状态。

        // 新增字段。
        map.put("smoke_exhaust_time", 0);
        map.put("smoke_exhaust_frequency", 0);
        map.put("smoke_exhaust_time_show", 0);
        return map;
    }

    public static Map deviceQuery2() {
        Map map = new HashMap();
        map.put(type_CMD, typeR);

        map.put("front_bearing_temperature", 0);
        map.put("back_bearing_temperature", 0);
        map.put("oxygen_content", 0);
        map.put("running_time", 0);
        return map;
    }

    public static Map deviceQuery3() {
        Map map = new HashMap();
        map.put(type_CMD, typeR);

//        map.put("electricity_today", 0);
        map.put("electricity_total", 0);
        return map;
    }









    // 得到各个bit位的值。
    public static boolean[] fault2BooleanArray(int result) {
        int r32768 = result & 0x8000;
        int r16384 = result & 0x4000;
        int r8192 = result & 0x2000;
        int r4096 = result & 0x1000;

        int r2048 = result & 0x0800;
        int r1024 = result & 0x0400;
        int r512 = result & 0x0200;
        int r256 = result & 0x0100;

        int r128 = result & 0x0080;
        int r64 = result & 0x0040;
        int r32 = result & 0x0020;
        int r16 = result & 0x0010;
        int r8 = result & 0x0008;
        int r4 = result & 0x0004;
        int r2 = result & 0x0002;
        int r1 = result & 0x0001;

        boolean bit0 = (r1 == 0x0001) ? true : false;
        boolean bit2 = (r2 == 0x0002) ? true : false;
        boolean bit4 = (r4 == 0x0004) ? true : false;
        boolean bit8 = (r8 == 0x0008) ? true : false;

        boolean bit16 = (r16 == 0x0010) ? true : false;
        boolean bit32 = (r32 == 0x0020) ? true : false;
        boolean bit64 = (r64 == 0x0040) ? true : false;
        boolean bit128 = (r128 == 0x0080) ? true : false;

        // ----------------------
        boolean bit256 = (r256 == 0x0100) ? true : false;
        boolean bit512 = (r512 == 0x0200) ? true : false;
        boolean bit1024 = (r1024 == 0x0400) ? true : false;
        boolean bit2048 = (r2048 == 0x0800) ? true : false;

        boolean bit4096 = (r4096 == 0x1000) ? true : false;
        boolean bit8192 = (r8192 == 0x2000) ? true : false;
        boolean bit16384 = (r16384 == 0x4000) ? true : false;
        boolean bit32768 = (r32768 == 0x8000) ? true : false;

        // 各bit的结果。
        boolean[] faults = {bit0, bit2, bit4, bit8, bit16, bit32, bit64, bit128, bit256, bit512, bit1024, bit2048,
                bit4096, bit8192, bit16384, bit32768};
        return faults;
    }

}
